package com.banksystem.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.banksystem.Util.TokenUtil;
import com.banksystem.entity.Activity;
import com.banksystem.service.Activityservice;

@Controller
public class sthdController {

	@Autowired
	private Activityservice ser;
	@Autowired
	private TokenUtil tokenUtil;
	/*
	 * 添加活动
	 */
	@RequestMapping("addhd")
	public String addhd(Model model,HttpServletRequest request) {
		String username = tokenUtil.findUsernameBytoken(request);
		model.addAttribute("gname",username);
		return "sthd/addhuodong";
	}
	@RequestMapping("add")
	public String add(String name,String gname,String date1 ,String date2,String master,String content) {
		ser.addhd(name, gname, date1, date2, master, content);
		return "sthd/addhuodong";
	}
	/*
	 * 活动管理
	 */
	@RequestMapping("sthdgl")
	public String sthdgl(HttpServletRequest request,Model model) {
		//String gname = tokenUtil.findUsernameBytoken(request);
		String gname = (String) request.getSession().getAttribute("gname");
		List<Activity> list;
		if(gname.equals("admin")) {
			list=ser.adminfindActivityAll();
		}else {
			list=ser.findActivityAll(gname);
		}

		model.addAttribute("Activitylist", list);
		return "sthd/sthdgl";
	}
	/*
	 * 删除
	 */
	@RequestMapping("deteleActivity")
	public String deteleActivity(String aid) {
		ser.deleteactivity(aid);
		return "forward:sthdgl.do";
	}
	/*
	 * 搜索
	 */
	@RequestMapping("hdseach")
	public @ResponseBody List<Activity> seach(String seach,HttpServletRequest request) {
		String gname=tokenUtil.findUsernameBytoken(request);
		List<Activity> list=ser.findActivityAlllike(seach,gname);
		return list;
	}
}
